package com.lyh.hkcloud.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.widget.*;
import cn.yhq.validate.ValidateManager;
import com.lyh.hkcloud.MainActivity;
import com.lyh.hkcloud.R;
import com.lyh.hkcloud.base.BaseActivity;
import com.lyh.hkcloud.base.ModuleActivity;
import com.lyh.hkcloud.constants.BusinessConstants;
import com.lyh.hkcloud.constants.HttpUrlComstants;
import com.lyh.hkcloud.dialog.NetworkDialog;
import com.lyh.hkcloud.module.common.Loading;
import com.lyh.hkcloud.service.UserService;
import com.lyh.hkcloud.util.base.SaveData;
import com.lyh.hkcloud.util.base.ToastUtils;
import com.lyh.hkcloud.util.base.ViewUtil;
import com.lyh.hkcloud.util.http.HttpClient;

import java.io.InputStream;
import java.util.HashMap;

public class LoginActivity extends BaseActivity implements View.OnClickListener {

    private EditText et_account;
    private EditText et_password;
    private Button btn_login;
//    private LinearLayout llSatellite;
//    private LinearLayout llDd;
    private LinearLayout llEnterprise;
    private LinearLayout llAccountNumber;

    private TextView tvEnterpriseAccount;
    private TextView tvAccountNumber;

    private UserService userService;

    private String loginMode = HttpUrlComstants.ENTERPRISE;

    @Override
    protected Activity getActivity() {
        return this;
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_login;
    }

    @Override
    protected int getSubmitResId() {
        return R.id.btn_login;
    }

    @Override
    protected void onBeginInit() {
        userService = new UserService(com.lyh.hkcloud.activity.LoginActivity.this);
    }

    @Override
    protected void initView() {
        et_account = findViewById(R.id.et_account);
        et_password = findViewById(R.id.et_password);
        btn_login = findViewById(R.id.btn_login);

//        llSatellite = findViewById(R.id.ll_satellite);
//        llDd = findViewById(R.id.ll_dd);
        llEnterprise = findViewById(R.id.ll_enterprise);
        llAccountNumber = findViewById(R.id.ll_account_number);
        tvEnterpriseAccount = findViewById(R.id.tv_enterprise_account);
        tvAccountNumber = findViewById(R.id.tv_account_number);

//        llSatellite.setOnClickListener(this);
//        llDd.setOnClickListener(this);
        llEnterprise.setOnClickListener(this);
        llAccountNumber.setOnClickListener(this);

        getSupportActionBar().hide();
        et_account.setText("");
        et_password.setText("");

    }

    @Override
    protected void initEvent() {
         /*String username = SaveData.getString(this, "username");
        String password = SaveData.getString(this, "password");
        et_account.setText("");
        et_password.setText("");*/
        getSupportActionBar().hide();
    }

    @Override
    protected void initValidateManager(ValidateManager validateManager) {
        validateManager.addValidateRequiredItem(et_account, "帐号不可为空！");
        validateManager.addValidateRequiredItem(et_password, "密码不可为空！");
    }

    @Override
    protected void onSubmit() {
        showProgressDialog("提示","登陆中");
        btn_login.setEnabled(false);
        userService.login(loginMode,et_account.getText().toString(), et_password.getText().toString(), MainActivity.class, com.lyh.hkcloud.activity.LoginActivity.class, null);
        btn_login.setEnabled(true);
        hideProgressDialog();
    }

    @Override
    protected void initData() {

    }

    private  ProgressDialog progressDialog;
    /**
     * 提示加载
     */
    public  void showProgressDialog(String title, String message) {
        if (progressDialog == null) {

            progressDialog = ProgressDialog.show(LoginActivity.this, title, message, true, false);
        } else if (progressDialog.isShowing()) {
            progressDialog.setTitle(title);
            progressDialog.setMessage(message);
        }

        progressDialog.show();

    }

    /**
     * 隐藏提示加载
     */
    public void hideProgressDialog() {

        if (progressDialog != null && progressDialog.isShowing()) {
            progressDialog.dismiss();
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
//            case R.id.ll_satellite:
//            case R.id.ll_dd:
//                ToastUtils.makeText(this, "暂不支持", ToastUtils.LENGTH_SHORT).show();
//                break;
            case R.id.ll_enterprise:

                loginMode = HttpUrlComstants.ACCOUNT_NUMBER;
                ToastUtils.makeText(this, "切换至账号登录", ToastUtils.LENGTH_SHORT).show();
                break;
            case R.id.ll_account_number:

                loginMode = HttpUrlComstants.ENTERPRISE;
                ToastUtils.makeText(this, "切换至企业账号登录", ToastUtils.LENGTH_SHORT).show();
                break;
            default:
        }
    }
}
